package de.graffiti.paint;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

import org.apache.batik.svggen.SVGGraphics2D;

import de.graffiti.services.AppletUploadService;
import de.graffiti.services.AppletUploadServiceService;

public class ExportToWebservice implements Output
{

	private ImageInfo image;

	public ExportToWebservice(ImageInfo image)
	{
		this.image = image;

	}

	public String export(SVGGraphics2D svgGenerator) throws IOException
	{

		// Finally, stream out SVG to the standard output using
		// UTF-8 encoding.
		boolean useCSS = true; // we want to use CSS style attributes

		AppletUploadServiceService service = new AppletUploadServiceService();
		AppletUploadService upload = service.getAppletUploadServicePort();

		Writer out;
		String content;
		OutputStream bout = new ByteArrayOutputStream();
		out = new OutputStreamWriter(bout, "UTF-8");
		svgGenerator.stream(out, useCSS);
		content = bout.toString();

		String result = upload.uploadItem(image.getSessionid(), image.getWallpaperid(), "Anonymous", content, "xml", 0, 0, 0, 0);
		System.out.println(result);
		return result;
	}

	// public static void main(String[] args) {
	// AppletUploadServiceService service = new AppletUploadServiceService();
	// AppletUploadService upload = service.getAppletUploadServicePort();
	//		
	//		
	//		
	// byte[] content;
	//		
	// content = bout.toString();
	// String result = upload.uploadItem(image.getSessionid(),
	// image.getWallpaperid(), "Anonymous", content, "xml", 0, 0, 0, 0);
	// }

}
